package com.ssyt.yt1.day7;

/**
 * 动物
 * 
 * @author Administrator
 *
 */
class Animal extends Object {

	public Animal() {
		System.out.println("grandFather...");
	}
}

/**
 * 人
 * 
 * @author Administrator
 *
 */
class Person extends Animal {

	private String name;
	private int age;
	private int gender;
	private String hobby;
	private String description;

	public Person() {
		// 这里super()是调用Object类的空的构造方法，它是隐式存在的，你也可以不写！
		super();
	}

	public Person(String name, int age, int gender, String hobby,
			String description) {
		super();
		this.name = name;
		this.age = age;
		this.gender = gender;
		this.hobby = hobby;
		this.description = description;
		System.out.println("parent...");
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public int getGender() {
		return gender;
	}

	public void setGender(int gender) {
		this.gender = gender;
	}

	public String getHobby() {
		return hobby;
	}

	public void setHobby(String hobby) {
		this.hobby = hobby;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

}

/**
 * 学生
 * 
 * @author Administrator
 *
 */
class Student extends Person {

	public Student() {
		// super();
	}

	public Student(String name, int age, int gender, String hobby,
			String description) {
		// 调用父类的设置值的构造方法，注意它跟this()调用本类的构造方法一样，必须要写在首行！
		super(name, age, gender, hobby, description);
		System.out.println("child...");
	}

	@Override
	public String toString() {
		return "Student [getName()=" + getName() + ", getAge()=" + getAge()
				+ ", getGender()=" + getGender() + ", getHobby()=" + getHobby()
				+ ", getDescription()=" + getDescription() + "]";
	}

}

/**
 * 老师
 * 
 * @author Administrator
 *
 */
class Teacher extends Person {

	private double salary;

	public Teacher() {
		super();
	}

	public Teacher(String name, int age, int gender, String hobby,
			String description, double salary) {
		super(name, age, gender, hobby, description);
		this.salary = salary;
	}

	public double getSalary() {
		return salary;
	}

	public void setSalary(double salary) {
		this.salary = salary;
	}

}

/**
 * 工人
 * 
 * @author Administrator
 *
 */
class Worker extends Person {

	private double salary;

	public Worker() {
		super();
	}

	public Worker(String name, int age, int gender, String hobby,
			String description, double salary) {
		super(name, age, gender, hobby, description);
		this.salary = salary;
	}

	public double getSalary() {
		return salary;
	}

	public void setSalary(double salary) {
		this.salary = salary;
	}

}

/**
 * <pre>
 * 继承（解决代码的重用）：
 * 1、通过extends关键字实现
 * 2、构造方法不能被继承
 * 3、如果一类的构造方法被重载了，一定记得要把它的空的构造方法声明出来，这是一个好习惯！
 * 4、在实例化子类的时候，先会去实例化父类（先调用父类的构造方法再调用子类的构造方法）
 * </pre>
 * 
 * @author Administrator
 *
 */
public class InheritanceDemo1 {

	public static void main(String[] args) {
		Student student = new Student("小三", 18, 1, "爱好当小三", "我是一个好小三！");

		// Teacher teacher = new Teacher("高富帅", 18, 1, "爱好当高富帅", "我是一个好高富帅！",
		// 999999999);
		// Worker worker = new Worker("碉堡", 18, 1, "爱好当小碉堡", "我是一个好小碉堡！", 0x1);
	}
}
